home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqtools / PCX.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-18  |  16.1 KB  |  675 lines

  1. /*
  2.  * pcxtoppm.c - Converts from a PC Paintbrush PCX file to a PPM file.
  3.  *
  4.  * Copyright (c) 1990 by Michael Davidson
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation.
  11.  *
  12.  * This file is provided AS IS with no warranties of any kind.  The author
  13.  * shall have no liability with respect to the infringement of copyrights,
  14.  * trade secrets or any patents by this file or any part thereof.  In no
  15.  * event will the author be liable for any lost revenue or profits or
  16.  * other special, indirect and consequential damages.
  17.  *
  18.  */
  19.  
  20. #define    PCX_MAGIC    0x0a                    /* PCX magic number               */
  21. #define    PCX_HDR_SIZE    128                    /* size of PCX header             */
  22. #define    PCX_256_COLORS    0x0c                    /* magic number for 256 colors    */
  23.  
  24. #define    MAXCOLORS       256
  25. #define    MAXPLANES    4
  26. #define    PCX_MAXVAL    255
  27.  
  28. static void read_pcx_image ARGS((FILE * fp, unsigned char *buf, int BytesPerLine, int Planes, int Height));
  29. static void pcx_planes_to_pixels ARGS((unsigned char *pixels, unsigned char *bitplanes, int bytesperline, int planes, int bitsperpixel));
  30. static void pcx_unpack_pixels ARGS((unsigned char *pixels, unsigned char *bitplanes, int bytesperline, int planes, int bitsperpixel));
  31. static int GetByte ARGS((FILE * fp));
  32. static int GetWord ARGS((FILE * fp));
  33.  
  34. int main(argc, argv)
  35.     int argc;
  36.     char *argv[];
  37. {
  38.   register int i;
  39.   FILE *ifp;
  40.   char *ifname;
  41.   int Version;
  42.   int Xmin, Ymin, Xmax, Ymax;
  43.   int Width, Height;
  44.   register int x, y;
  45.   int Planes;
  46.   int BitsPerPixel;
  47.   int BytesPerLine;
  48.   unsigned char Red[MAXCOLORS], Green[MAXCOLORS], Blue[MAXCOLORS];
  49.   unsigned char *pcximage;
  50.   unsigned char *pcxplanes;
  51.   unsigned char *pcxpixels;
  52.   pixel **pixels;
  53.  
  54.   ppm_init(&argc, argv);
  55.  
  56.   switch (argc) {
  57.     case 1:
  58.       ifname = "standard input";
  59.       ifp = stdin;
  60.       break;
  61.     case 2:
  62.       ifname = argv[1];
  63.       ifp = pm_openr(ifname);
  64.       break;
  65.     default:
  66.       pm_usage("[pcxfile]");
  67.       break;
  68.   }
  69.  
  70.   /*
  71.    * read the PCX header
  72.    */
  73.   if (GetByte(ifp) != PCX_MAGIC)
  74.     pm_error("%s is not a PCX file", ifname);
  75.  
  76.   Version = GetByte(ifp);                    /* get version #                       */
  77.  
  78.   if (GetByte(ifp) != 1)                    /* check for PCX run length encoding      */
  79.     pm_error("%s has unknown encoding scheme", ifname);
  80.  
  81.   BitsPerPixel = GetByte(ifp);
  82.   Xmin = GetWord(ifp);
  83.   Ymin = GetWord(ifp);
  84.   Xmax = GetWord(ifp);
  85.   Ymax = GetWord(ifp);
  86.  
  87.   Width = (Xmax - Xmin) + 1;
  88.   Height = (Ymax - Ymin) + 1;
  89.  
  90.   (void)GetWord(ifp);                        /* ignore horizontal resolution */
  91.   (void)GetWord(ifp);                        /* ignore vertical resolution   */
  92.  
  93.   /*
  94.    * get the 16-color color map
  95.    */
  96.   for (i = 0; i < 16; i++) {
  97.     Red[i] = GetByte(ifp);
  98.     Green[i] = GetByte(ifp);
  99.     Blue[i] = GetByte(ifp);
  100.   }
  101.  
  102.   (void)GetByte(ifp);                        /* skip reserved byte    */
  103.   Planes = GetByte(ifp);                    /* # of color planes     */
  104.   BytesPerLine = GetWord(ifp);                    /* # of bytes per line   */
  105.   (void)GetWord(ifp);                        /* ignore palette info   */
  106.  
  107.   /*
  108.    * check that we can handle this image format
  109.    */
  110.   switch (BitsPerPixel) {
  111.     case 1:
  112.       if (Planes > 4)
  113.     pm_error("can't handle image with more than 4 planes");
  114.       break;
  115.  
  116.     case 2:
  117.     case 4:
  118.     case 8:
  119.       if (Planes == 1)
  120.     break;
  121.     default:
  122.       pm_error("can't handle %d bits per pixel image with %d planes",
  123.            BitsPerPixel, Planes);
  124.   }
  125.  
  126.   /*
  127.    * read the pcx format image
  128.    */
  129.   fseek(ifp, (long)PCX_HDR_SIZE, 0);
  130.   pcximage = (unsigned char *)pm_allocrow(BytesPerLine * Planes, Height);
  131.   read_pcx_image(ifp, pcximage, BytesPerLine, Planes, Height);
  132.  
  133.   /*
  134.    * 256 color images have their color map at the end of the file
  135.    * preceeded by a magic byte
  136.    */
  137.   if (BitsPerPixel == 8) {
  138.     if (GetByte(ifp) != PCX_256_COLORS)
  139.       pm_error("bad color map signature");
  140.  
  141.     for (i = 0; i < MAXCOLORS; i++) {
  142.       Red[i] = GetByte(ifp);
  143.       Green[i] = GetByte(ifp);
  144.       Blue[i] = GetByte(ifp);
  145.     }
  146.   }
  147.  
  148.   pixels = ppm_allocarray(Width, Height);
  149.   pcxpixels = (unsigned char *)pm_allocrow(Width + 7, 1);
  150.  
  151.   /*
  152.    * convert the image
  153.    */
  154.   for (y = 0; y < Height; y++) {
  155.     pcxplanes = pcximage + (y * BytesPerLine * Planes);
  156.  
  157.     if (Planes == 1) {
  158.       pcx_unpack_pixels(pcxpixels, pcxplanes,
  159.             BytesPerLine, Planes, BitsPerPixel);
  160.     }
  161.     else {
  162.       pcx_planes_to_pixels(pcxpixels, pcxplanes,
  163.                BytesPerLine, Planes, BitsPerPixel);
  164.     }
  165.  
  166.     for (x = 0; x < Width; x++) {
  167.       i = pcxpixels[x];
  168.       PPM_ASSIGN(pixels[y][x], Red[i], Green[i], Blue[i]);
  169.     }
  170.   }
  171.  
  172.   pm_close(ifp);
  173.  
  174.   ppm_writeppm(stdout, pixels, Width, Height, (pixval) 255, 0);
  175.  
  176.   pm_close(stdout);
  177.  
  178.   exit(0);
  179. }
  180.  
  181. static void read_pcx_image(fp, buf, BytesPerLine, Planes, Height)
  182.     FILE *fp;
  183.     unsigned char *buf;
  184.     int BytesPerLine;
  185.     int Planes;
  186.     int Height;
  187. {
  188.   int c;
  189.   int nbytes;
  190.   int count;
  191.  
  192.   nbytes = BytesPerLine * Planes * Height;
  193.  
  194.   while (nbytes > 0) {
  195.     c = GetByte(fp);
  196.     if ((c & 0xc0) != 0xc0) {
  197.       *buf++ = c;
  198.       --nbytes;
  199.       continue;
  200.     }
  201.  
  202.     count = c & 0x3f;
  203.     c = GetByte(fp);
  204.     if (count > nbytes)
  205.       pm_error("repeat count spans end of image, count = %d, nbytes = %d", count, nbytes);
  206.  
  207.     nbytes -= count;
  208.     while (--count >= 0)
  209.       *buf++ = c;
  210.   }
  211. }
  212.  
  213. /*
  214.  * convert multi-plane format into 1 pixel per byte
  215.  */
  216. static void pcx_planes_to_pixels(pixels, bitplanes, bytesperline, planes, bitsperpixel)
  217.     unsigned char *pixels;
  218.     unsigned char *bitplanes;
  219.     int bytesperline;
  220.     int planes;
  221.     int bitsperpixel;
  222. {
  223.   int i, j;
  224.   int npixels;
  225.   unsigned char *p;
  226.  
  227.   if (planes > 4)
  228.     pm_error("can't handle more than 4 planes");
  229.   if (bitsperpixel != 1)
  230.     pm_error("can't handle more than 1 bit per pixel");
  231.  
  232.   /*
  233.    * clear the pixel buffer
  234.    */
  235.   npixels = (bytesperline * 8) / bitsperpixel;
  236.   p = pixels;
  237.   while (--npixels >= 0)
  238.     *p++ = 0;
  239.  
  240.   /*
  241.    * do the format conversion
  242.    */
  243.   for (i = 0; i < planes; i++) {
  244.     int pixbit, bits, mask;
  245.  
  246.     p = pixels;
  247.     pixbit = (1 << i);
  248.     for (j = 0; j < bytesperline; j++) {
  249.       bits = *bitplanes++;
  250.       for (mask = 0x80; mask != 0; mask >>= 1, p++)
  251.     if (bits & mask)
  252.       *p |= pixbit;
  253.     }
  254.   }
  255. }
  256.  
  257. /*
  258.  * convert packed pixel format into 1 pixel per byte
  259.  */
  260. static void pcx_unpack_pixels(pixels, bitplanes, bytesperline, planes, bitsperpixel)
  261.     unsigned char *pixels;
  262.     unsigned char *bitplanes;
  263.     int bytesperline;
  264.     int planes;
  265.     int bitsperpixel;
  266. {
  267.   register int bits;
  268.  
  269.   if (planes != 1)
  270.     pm_error("can't handle packed pixels with more than 1 plane");
  271.   if (bitsperpixel == 8) {
  272.     while (--bytesperline >= 0)
  273.       *pixels++ = *bitplanes++;
  274.   }
  275.   else if (bitsperpixel == 4) {
  276.     while (--bytesperline >= 0) {
  277.       bits = *bitplanes++;
  278.       *pixels++ = (bits >> 4) & 0x0f;
  279.       *pixels++ = (bits) & 0x0f;
  280.     }
  281.   }
  282.   else if (bitsperpixel == 2) {
  283.     while (--bytesperline >= 0) {
  284.       bits = *bitplanes++;
  285.       *pixels++ = (bits >> 6) & 0x03;
  286.       *pixels++ = (bits >> 4) & 0x03;
  287.       *pixels++ = (bits >> 2) & 0x03;
  288.       *pixels++ = (bits) & 0x03;
  289.     }
  290.   }
  291.   else if (bitsperpixel == 1) {
  292.     while (--bytesperline >= 0) {
  293.       bits = *bitplanes++;
  294.       *pixels++ = ((bits & 0x80) != 0);
  295.       *pixels++ = ((bits & 0x40) != 0);
  296.       *pixels++ = ((bits & 0x20) != 0);
  297.       *pixels++ = ((bits & 0x10) != 0);
  298.       *pixels++ = ((bits & 0x08) != 0);
  299.       *pixels++ = ((bits & 0x04) != 0);
  300.       *pixels++ = ((bits & 0x02) != 0);
  301.       *pixels++ = ((bits & 0x01) != 0);
  302.     }
  303.   }
  304. }
  305.  
  306. static int GetByte(fp)
  307.     FILE *fp;
  308. {
  309.   int c;
  310.  
  311.   if ((c = getc(fp)) == EOF)
  312.     pm_error("unexpected end of file");
  313.  
  314.   return c;
  315. }
  316.  
  317. static int GetWord(fp)
  318.     FILE *fp;
  319. {
  320.   int c;
  321.  
  322.   c = GetByte(fp);
  323.   c |= (GetByte(fp) << 8);
  324.   return c;
  325. }
  326.  
  327. /* ppmtopcx.c - read a portable pixmap and produce a PCX file
  328.  *
  329.  * Copyright (C) 1990 by Michael Davidson.
  330.  *
  331.  * Permission to use, copy, modify, and distribute this software and its
  332.  * documentation for any purpose and without fee is hereby granted, provided
  333.  * that the above copyright notice appear in all copies and that both that
  334.  * copyright notice and this permission notice appear in supporting
  335.  * documentation.  This software is provided "as is" without express or
  336.  * implied warranty.
  337.  */
  338.  
  339. #define MAXCOLORS    256
  340. #define    MAXPLANES    4
  341.  
  342. /*
  343.  * Pointer to function returning an int
  344.  */
  345. typedef void (*vfunptr) ARGS((int, int, unsigned char *, int, int));
  346.  
  347. static void PCXEncode ARGS((FILE * fp, int GWidth, int GHeight, int Colors, int Red[], int Green[], int Blue[], vfunptr GetPlanes));
  348. static void PutPlane ARGS((FILE * fp, unsigned char *buf, int Size));
  349. static void ReadPlanes ARGS((int y, int width, unsigned char *buf, int planes, int bits));
  350. static void Putword ARGS((int w, FILE * fp));
  351. static void Putbyte ARGS((int b, FILE * fp));
  352.  
  353. static pixel **pixels;
  354. static colorhash_table cht;
  355.  
  356. int main(argc, argv)
  357.     int argc;
  358.     char *argv[];
  359. {
  360.   FILE *ifp;
  361.   int argn, rows, cols, colors, i;
  362.   pixval maxval;
  363.   pixel black_pixel;
  364.   colorhist_vector chv;
  365.   int Red[MAXCOLORS], Green[MAXCOLORS], Blue[MAXCOLORS];
  366.   char *usage = "[ppmfile]";
  367.  
  368.   ppm_init(&argc, argv);
  369.  
  370.   argn = 1;
  371.  
  372.   if (argn < argc) {
  373.     ifp = pm_openr(argv[argn]);
  374.     ++argn;
  375.   }
  376.   else
  377.     ifp = stdin;
  378.  
  379.   if (argn != argc)
  380.     pm_usage(usage);
  381.  
  382.   pixels = ppm_readppm(ifp, &cols, &rows, &maxval);
  383.  
  384.   pm_close(ifp);
  385.  
  386.   /* Figure out the colormap. */
  387.   pm_message("computing colormap...");
  388.   chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors);
  389.   if (chv == (colorhist_vector) 0)
  390.     pm_error(
  391.           "too many colors - try doing a 'ppmquant %d'", MAXCOLORS);
  392.   pm_message("%d colors found", colors);
  393.  
  394.   /* Force black to slot 0 if possible. */
  395.   PPM_ASSIGN(black_pixel, 0, 0, 0);
  396.   ppm_addtocolorhist(chv, &colors, MAXCOLORS, &black_pixel, 0, 0);
  397.  
  398.   /* Now turn the ppm colormap into the appropriate PCX colormap. */
  399.   if (maxval > 255)
  400.     pm_message(
  401.         "maxval is not 255 - automatically rescaling colors");
  402.   for (i = 0; i < colors; ++i) {
  403.     if (maxval == 255) {
  404.       Red[i] = PPM_GETR(chv[i].color);
  405.       Green[i] = PPM_GETG(chv[i].color);
  406.       Blue[i] = PPM_GETB(chv[i].color);
  407.     }
  408.     else {
  409.       Red[i] = (int)PPM_GETR(chv[i].color) * 255 / maxval;
  410.       Green[i] = (int)PPM_GETG(chv[i].color) * 255 / maxval;
  411.       Blue[i] = (int)PPM_GETB(chv[i].color) * 255 / maxval;
  412.     }
  413.   }
  414.  
  415.   /* And make a hash table for fast lookup. */
  416.   cht = ppm_colorhisttocolorhash(chv, colors);
  417.   ppm_freecolorhist(chv);
  418.  
  419.   /* All set, let's do it. */
  420.   PCXEncode(stdout, cols, rows, colors, Red, Green, Blue, ReadPlanes);
  421.  
  422.   exit(0);
  423. }
  424.  
  425. /*****************************************************************************
  426.  *
  427.  * PCXENCODE.C    - PCX Image compression interface
  428.  *
  429.  * PCXEncode( FName, GHeight, GWidth, Colors, Red, Green, Blue, GetPlanes )
  430.  *
  431.  *****************************************************************************/
  432.  
  433. /* public */
  434.  
  435. static void PCXEncode(fp, GWidth, GHeight, Colors, Red, Green, Blue, GetPlanes)
  436.     FILE *fp;
  437.     int GWidth, GHeight;
  438.     int Colors;
  439.     int Red[], Green[], Blue[];
  440.     vfunptr GetPlanes;
  441. {
  442.   int BytesPerLine;
  443.   int Planes;
  444.   int BitsPerPixel;
  445.   unsigned char *buf;
  446.   int i;
  447.   int n;
  448.   int y;
  449.  
  450.   /*
  451.    * select number of planes and number of bits
  452.    * per pixel according to number of colors
  453.    */
  454.   /*
  455.    * 16 colors or less are handled as 1 bit per pixel
  456.    * with 1, 2, 3 or 4 color planes.
  457.    * more than 16 colors are handled as 8 bits per pixel
  458.    * with 1 plane
  459.    */
  460.   if (Colors > 16) {
  461.     BitsPerPixel = 8;
  462.     Planes = 1;
  463.   }
  464.   else {
  465.     BitsPerPixel = 1;
  466.     if (Colors > 8)
  467.       Planes = 4;
  468.     else if (Colors > 4)
  469.       Planes = 3;
  470.     else if (Colors > 2)
  471.       Planes = 2;
  472.     else
  473.       Planes = 1;
  474.   }
  475.  
  476.   /*
  477.    * Write the PCX header
  478.    */
  479.   Putbyte(0x0a, fp);                        /* .PCX magic number            */
  480.   Putbyte(0x05, fp);                        /* PC Paintbrush version        */
  481.   Putbyte(0x01, fp);                        /* .PCX run length encoding     */
  482.   Putbyte(BitsPerPixel, fp);                    /* bits per pixel               */
  483.  
  484.   Putword(0, fp);                        /* x1   - image left            */
  485.   Putword(0, fp);                        /* y1   - image top             */
  486.   Putword(GWidth - 1, fp);                    /* x2   - image right           */
  487.   Putword(GHeight - 1, fp);                    /* y2   - image bottom          */
  488.  
  489.   Putword(GWidth, fp);                        /* horizontal resolution        */
  490.   Putword(GHeight, fp);                        /* vertical resolution          */
  491.  
  492.   /*
  493.    * Write out the Color Map for images with 16 colors or less
  494.    */
  495.   n = (Colors <= 16) ? Colors : 16;
  496.   for (i = 0; i < n; ++i) {
  497.     Putbyte(Red[i], fp);
  498.     Putbyte(Green[i], fp);
  499.     Putbyte(Blue[i], fp);
  500.   }
  501.   for (; i < 16; ++i) {
  502.     Putbyte(255, fp);
  503.     Putbyte(255, fp);
  504.     Putbyte(255, fp);
  505.   }
  506.  
  507.   Putbyte(0, fp);                        /* reserved byte                */
  508.  
  509.   Putbyte(Planes, fp);                        /* number of color planes       */
  510.  
  511.   BytesPerLine = ((GWidth * BitsPerPixel) + 7) / 8;
  512.   Putword(BytesPerLine, fp);                    /* number of bytes per scanline */
  513.  
  514.   Putword(1, fp);                        /* pallette info                */
  515.  
  516.   for (i = 0; i < 58; ++i)                    /* fill to end of header  */
  517.     Putbyte(0, fp);
  518.  
  519.   buf = (unsigned char *)malloc(MAXPLANES * BytesPerLine);
  520.  
  521.   for (y = 0; y < GHeight; ++y) {
  522.     (*GetPlanes) (y, GWidth, buf, Planes, BitsPerPixel);
  523.  
  524.     for (i = 0; i < Planes; ++i)
  525.       PutPlane(fp, buf + (i * BytesPerLine), BytesPerLine);
  526.   }
  527.  
  528.   /*
  529.    * color map for > 16 colors is at end of file
  530.    */
  531.   if (Colors > 16) {
  532.     Putbyte(0x0c, fp);                        /* magic for 256 colors */
  533.     for (i = 0; i < Colors; ++i) {
  534.       Putbyte(Red[i], fp);
  535.       Putbyte(Green[i], fp);
  536.       Putbyte(Blue[i], fp);
  537.     }
  538.     for (; i < MAXCOLORS; ++i) {
  539.       Putbyte(255, fp);
  540.       Putbyte(255, fp);
  541.       Putbyte(255, fp);
  542.     }
  543.   }
  544.  
  545.   fclose(fp);
  546. }
  547.  
  548. static void PutPlane(fp, buf, Size)
  549.     FILE *fp;
  550.     unsigned char *buf;
  551.     int Size;
  552. {
  553.   unsigned char *end;
  554.   int c;
  555.   int previous;
  556.   int count;
  557.  
  558.   end = buf + Size;
  559.  
  560.   previous = *buf++;
  561.   count = 1;
  562.  
  563.   while (buf < end) {
  564.     c = *buf++;
  565.     if (c == previous && count < 63) {
  566.       ++count;
  567.       continue;
  568.     }
  569.  
  570.     if (count > 1 || (previous & 0xc0) == 0xc0) {
  571.       count |= 0xc0;
  572.       Putbyte(count, fp);
  573.     }
  574.     Putbyte(previous, fp);
  575.     previous = c;
  576.     count = 1;
  577.   }
  578.  
  579.   if (count > 1 || (previous & 0xc0) == 0xc0) {
  580.     count |= 0xc0;
  581.     Putbyte(count, fp);
  582.   }
  583.   Putbyte(previous, fp);
  584. }
  585.  
  586. static unsigned long PixMap[8][16] =
  587. {
  588.   0x00000000L, 0x00000080L, 0x00008000L, 0x00008080L,
  589.   0x00800000L, 0x00800080L, 0x00808000L, 0x00808080L,
  590.   0x80000000L, 0x80000080L, 0x80008000L, 0x80008080L,
  591.   0x80800000L, 0x80800080L, 0x80808000L, 0x80808080L,
  592. };
  593.  
  594. static void ReadPlanes(y, width, buf, planes, bits)
  595.     int y;
  596.     int width;
  597.     unsigned char *buf;
  598.     int planes;
  599.     int bits;
  600. {
  601.   static int first_time = 1;
  602.   unsigned char *plane0, *plane1, *plane2, *plane3;
  603.   int i, j, x;
  604.  
  605.   /*
  606.    * 256 color, 1 plane, 8 bits per pixel
  607.    */
  608.   if (planes == 1 && bits == 8) {
  609.     for (x = 0; x < width; ++x)
  610.       buf[x] = ppm_lookupcolor(cht, &pixels[y][x]);
  611.     return;
  612.   }
  613.  
  614.   /*
  615.    * must be 16 colors or less, 4 planes or less, 1 bit per pixel
  616.    */
  617.   if (first_time) {
  618.     for (i = 1; i < 8; ++i)
  619.       for (j = 0; j < 16; ++j)
  620.     PixMap[i][j] = PixMap[0][j] >> i;
  621.     first_time = 0;
  622.   }
  623.  
  624.   i = (width + 7) / 8;
  625.  
  626.   plane0 = buf;
  627.   plane1 = plane0 + i;
  628.   plane2 = plane1 + i;
  629.   plane3 = plane2 + i;
  630.  
  631.   i = 0;
  632.   x = 0;
  633.  
  634.   while (x < width) {
  635.     register unsigned long t;
  636.  
  637.     t = PixMap[0][ppm_lookupcolor(cht, &pixels[y][x++])];
  638.     t |= PixMap[1][ppm_lookupcolor(cht, &pixels[y][x++])];
  639.     t |= PixMap[2][ppm_lookupcolor(cht, &pixels[y][x++])];
  640.     t |= PixMap[3][ppm_lookupcolor(cht, &pixels[y][x++])];
  641.     t |= PixMap[4][ppm_lookupcolor(cht, &pixels[y][x++])];
  642.     t |= PixMap[5][ppm_lookupcolor(cht, &pixels[y][x++])];
  643.     t |= PixMap[6][ppm_lookupcolor(cht, &pixels[y][x++])];
  644.     t |= PixMap[7][ppm_lookupcolor(cht, &pixels[y][x++])];
  645.  
  646.     plane0[i] = t;
  647.     plane1[i] = t >> 8;
  648.     plane2[i] = t >> 16;
  649.     plane3[i++] = t >> 24;
  650.   }
  651. }
  652.  
  653. /*
  654.  * Write out a word to the PCX file
  655.  */
  656. static void Putword(w, fp)
  657.     int w;
  658.     FILE *fp;
  659. {
  660.   fputc(w & 0xff, fp);
  661.   fputc((w / 256) & 0xff, fp);
  662. }
  663.  
  664. /*
  665.  * Write out a byte to the PCX file
  666.  */
  667. static void Putbyte(b, fp)
  668.     int b;
  669.     FILE *fp;
  670. {
  671.   fputc(b & 0xff, fp);
  672. }
  673.  
  674. /* The End */
  675.